﻿using Microsoft.SharePoint;
using Microsoft.SharePoint.WebControls;
using SPFluid.ServiceLocation;
using SPFluid.UI.Presenters;
using SPFluid.UI.Views;

namespace SPFluid.UI.Controls
{
    public abstract class SPPageBase<TPresenter, TView> : LayoutsPageBase, ISPView
        where TPresenter : SPPresenterBase<TView>
        where TView : class, ISPView
    {
        private TPresenter presenter;

        public TPresenter Presenter
        {
            get
            {
                if (this.presenter == null)
                {
                    var serviceLocator = FluidServiceLocator.GetCurrent();

                    this.presenter = serviceLocator.GetInstance<TPresenter>();
                    this.presenter.View = this as TView;
                }

                return this.presenter;
            }
        }

        public SPSite CurrentSite
        {
            get
            {
                return this.Site;
            }
        }

        public SPWeb CurrentWeb
        {
            get
            {
                return this.Web;
            }
        }
    }
}